* set working directory and load the file:
use "Mexico LAPOP Special Study 2019 (20190604)_replication.dta", clear

* front end code 
set more off

set scheme s1mono

program rescale
 args oldvar newmin newmax
 qui sum `oldvar'
 local oldmin=r(min)
 local rangequota=(`newmax'-`newmin')/(r(max)-r(min))
 replace `oldvar'=(`oldvar'-`oldmin')*`rangequota'+`oldmin'+(`newmin'-`oldmin')
end

/* packages used:
ssc install coefplot
ssc install eststo
*/

**************************************************
*DATA CLEANING
**************************************************

************************
* create key variables *
************************

**** KEY INDEPENDENT VARIABLES ****

* independent variable: ITT
gen itt=.
replace itt=1 if mxvb3n1!=.c
replace itt=2 if mxvb3n2!=.c
replace itt=3 if premxvb3n3!=.c
replace itt=4 if premxvb3n4!=.c
replace itt=5 if premxvb3n5!=.c
replace itt=6 if premxvb3n6!=.c

lab define treat 1"Control" 2"Confidentiality Reminder" 3"Audio, No Reminder" 4"Audio, Confidentiality Reminder" 5"Audio, Anonymity Guarantee" 6"Audio, Anonymity & Confidentiality Assurances"
lab val itt treat

* audio versus other treatments
gen treat3=.
replace treat3=0 if itt==1 | itt==2
replace treat3=1 if inlist(itt, 3, 4, 5, 6)
*ttest nrvote, by(treat3)

lab define treat2 0 "Interviewer Administered" 1 "Audio Administered"
lab val treat3 treat2

* anonymity vs. other treatements
gen anontrt=0
replace anontrt=1 if itt==5 | itt==6

* reminder vs. other treatements
gen remindtrt=0
replace remindtrt=1 if itt==2 | itt==4

* any privacy reminder
gen privacytrt=.
replace privacytrt=0 if inlist(itt, 1,3)
replace privacytrt=1 if inlist(itt, 2, 4, 5, 6)

lab define privacytrt 0 "No Confidentiality Reminder" 1 "Confidentiality Reminder"
lab val privacytrt privacytrt

gen anonymous=.
replace anonymous=0 if inlist(itt, 3, 4)
replace anonymous=1 if inlist(itt, 5, 6)
lab define anonymous 0 "No Anonymity Guarantee" 1 "Anonymity Guarantee"
lab val anonymous anonymous

gen anon2=anonymous
replace anon2=0 if inlist(itt, 1, 2)

* REASSIGNED RESPONDENTS
gen reassigned = 0
replace reassigned = 1 if vb2==1 & premxvb3n3==2 | premxvb3n4==2 | premxvb3n5==2 | premxvb3n6==2
tab reassigned


**** DEPENDENT VARIABLES ****

* dependent variable: non-response to vote question
recode mxvb3n1 (.a .b=1)(else=0), gen(nrvote)
replace nrvote=1 if mxvb3n2==.a |  mxvb3n2==.b
replace nrvote=1 if mxvb3n3==.a |  mxvb3n3==.b
replace nrvote=1 if mxvb3n4==.a |  mxvb3n4==.b
replace nrvote=1 if mxvb3n5==.a |  mxvb3n5==.b
replace nrvote=1 if mxvb3n6==.a |  mxvb3n6==.b
replace nrvote=1 if mxvb3n1b==.a |  mxvb3n1b==.b
replace nrvote=1 if mxvb3n2b==.a |  mxvb3n2b==.b


* dependent variable: vote choice
gen vote=mxvb3n1
replace vote=mxvb3n2 if vote>5
replace vote=mxvb3n3 if vote>5
replace vote=mxvb3n4 if vote>5
replace vote=mxvb3n5 if vote>5
replace vote=mxvb3n6 if vote>5
replace vote=mxvb3n1b if vote>5
replace vote=mxvb3n2b if vote>5
replace vote=6 if vote==.a | vote==.b

lab define vote 1 "Blanco/ Nulo" 2 "AMLO" 3 "Anaya" 4 "Meade" 5 "Otro" 6 "Missing"
lab val vote vote

* vote for AMLO
recode vote(2=1)(1 3 4 5=0)(else=.), gen(AMLO)

* dependent variable: anonymity beliefs (mechanism)
recode mxcheckvb3(1=4 "A lot")(2=3 "Some")(3=2 "A little")(4=1 "None"), gen(anonbelief)

* dependent variable: survey satisfaction (mechanism)
recode mxssat1g(1=4 "A lot")(2=3 "Some")(3=2 "A little")(4=1 "None"), gen(svysat)
recode mxssat1h(1=4 "A lot")(2=3 "Some")(3=2 "A little")(4=1 "None"), gen(svysat2)
replace svysat=svysat2 if svysat>4

* dependent variable: audio satisfaction (mechanism)
recode mxssat2g(1=5 "Much more")(2=4 "More")(3=3 "Neither more nor less")(4=2 "Less")(5=1 "Much less"), gen(audiosat)
recode mxssat2h(1=5 "Much more")(2=4 "More")(3=3 "Neither more nor less")(4=2 "Less")(5=1 "Much less"), gen(audiosat2)
replace audiosat=audiosat2 if audiosat>5

gen trtsat=0
replace trtsat=1 if mxssat1g==.c

* DV: non-response to satisfaction items
recode svysat(1/4=0)(.a .b=1), gen(nrsvysat)
recode audiosat(1/5=0)(.a .b=1), gen(nraudiosat)


**** FUTBOL MEASURES ****

* independent variable: treatment condition (ITT)
gen fbtreat=.
replace fbtreat=0 if mxfutbl1!=.c
replace fbtreat=1 if premxfutbl==1
replace fbtreat=1 if mxfutbl1b!=.c
replace fbtreat=1 if mxfutbl2!=.c

* refused soccer treatment
recode premxfutbl(1=0)(2=1), gen(reassigned_fbl)

lab def fbtreat 0"Control" 1"Audio"
lab val fbtreat fbtreat

* dependent variable: nonresponse to soccer 
recode mxfutbl1 (.a .b=1)(else=0), gen(nrfutbol)
replace nrfutbol=1 if mxfutbl2==. & mxfutbl2!=.c

* independent variable - either audio condition
gen audiotrt=0
replace audiotrt=1 if treat3==1 | mxfutbl2!=.c

gen audiovote=.
replace audiovote=0 if inlist(itt, 1, 2)
replace audiovote=1 if itt>=3 & itt!=.


***************************
*** 	FIGURE 1		***
***************************

* difference of proportions tests
tab itt, gen(nitt)
prtest nrvote if inlist(itt,1, 2), by(nitt2) 
prtest nrvote if inlist(itt,1, 3), by(nitt3) 
prtest nrvote if inlist(itt,1, 4), by(nitt4) 
prtest nrvote if inlist(itt,1, 5), by(nitt5) 
prtest nrvote if inlist(itt,1, 6), by(nitt6) 

* ATE with no clustering
logit nrvote i.itt
margins, dydx(itt) atmeans post
eststo itt

* note that anonymity only is significantly different from audio with no reminder
test 5.itt=2.itt
test 5.itt=3.itt
test 5.itt=4.itt
test 5.itt=6.itt

coefplot itt, recast(scatter) drop(_cons) legend(off) xline(0, lpattern(dash)) levels(90 95) ///
         ylabel(1 "Confidentiality Reminder" 2 "Audio, No Reminder" 3 "Audio, Confidentiality Reminder" ///
		4 "Audio, Anonymity Guarantee" 5 `" "Audio, Anonymity &" "Confidentiality Assurances"', ///
		labsize(medium) ) title("") ciopts(recast(rcap)) ///
         xtitle("Change in Pr(Non-Response)", size(medium)) ytitle("") ///
		 mlab  format(%04.3f) mlabposition(12) mlabgap(*2) mlabsize(medium) ///
         xlabel(, labsize(medium) valuelabels format(%04.2f)) scheme(s1mono) name(itt, replace)



***********************************************************
*** 	FIGURE 2: effect of privacy treatments (H2)		***
***********************************************************

***** AUDIO
logit nrvote i.treat3 if itt<5
margins i.treat3, atmeans post
eststo audiotrt1

gen treat4=treat3
lab def treat4 1"Difference"
lab val treat4 treat4 
logit nrvote i.treat4 if itt<5
margins, dydx(i.treat4) post
eststo audiotrt2

**** PRIVACY TREATMENTS
logit nrvote i.privacytrt if itt<5 & itt!=.
margins i.privacytrt, atmeans post
eststo privacy1

gen privacy2=privacy
lab def privacy2 1"Difference"
lab val privacy2 privacy2
logit nrvote i.privacy2 if itt<5 & itt!=.
margins, dydx(i.privacy2) post
eststo privacy2

* CREATE COMBINED FIGURE
		
coefplot (audiotrt1, bcolor(gs7)) ///
		(audiotrt2, bcolor(gs11)) ///
		(privacy1, bcolor(gs7))  ///
		(privacy2, bcolor(gs11)) , recast(bar) drop(_cons) vert nooffset legend(off) ///
		yaxis(1 2) ylab(0 .02 .04 .06 .08 .1, axis(1) angle(0)) ///
		ylab(-.08 -.06 -.04 -.02 0, axis(2) angle(0)) ///
		ciopts(recast(rcap) color(gs3 gs3) fcolor(gs7*0.3)) citop levels(90 95) ///
		ylabel(, labsize(small) format(%04.2f) valuelabels) ///
		ylabel(, labsize(small) format(%04.2f) valuelabels axis(2))  ///
        ytitle("Pr(Non-Response)", size(medsmall) axis(1)) ///
		ytitle("Difference in Pr(Non-Response)", size(medsmall) axis(2)) ///
		xtitle("") xlabel(1 `" "No" "Reminder"' 2 `" "Confidentiality" "Reminder"' ///
		3 "Diff" 4 "Interviewer" 5 "Audio" 6 "Diff", labsize(medsmall)) ///
		ylabel(, labsize(small) valuelabels) ///
		ylabel(, labsize(small) valuelabels axis(2)) name(figure2, replace)



************************
****	FIGURE 3	****
************************

logit AMLO i.itt if estado==1001
eststo c31
margins i.itt, atmeans post
eststo amlo1001

test 1.itt==.577
test 2.itt==.577
test 3.itt==.577
test 4.itt==.577
test 5.itt==.577
test 6.itt==.577

logit AMLO i.itt if estado==1002
eststo c33
margins i.itt, atmeans post
eststo amlo1002

test 1.itt==.544
test 2.itt==.544
test 3.itt==.544
test 4.itt==.544
test 5.itt==.544
test 6.itt==.544

coefplot amlo1001 amlo1002,  ///
	 ylabel(1 "Control" 2 "Confidentiality Reminder" 3 "Audio, No Reminder" ///
	 4 "Audio, Confidentiality Reminder" 5 "Audio, Anonymity Guarantee" ///
	 6 `" "Audio, Anonymity &" "Confidentiality Assurances"', labsize(medium)) ///
	 title("") ciopts(recast(rcap)) levels(90 95) ///
	 xline(.544, lpattern(dash) lcolor(gs11)) ///
	 xline(.577, lpattern(dash)) xlab(, format(%04.2f)) scheme(s1mono) ///
	 msymbol(o) mlab format(%04.3f) mlabposition(12) mlabgap(*2) ///
	 p1(label(Mexico City (0.577))) ///
	 p2(label(Mexico State (0.544))) name(figure3, replace)
	

	
***********************
***		TABLE 2 	***
***********************

**Columns 1-2 (Anonymity Perceptions)
reg anonbelief treat3 privacytrt i.anon2
eststo anonb4

**Columsn 3-4 (Audio Question Enjoyment)
reg audiosat 0.fbtreat if vb2==1
eststo audiosat4

esttab anonb4 audiosat4, b(3) se(3) nogaps nopar label 

* missingness results reported in paper body
recode anonbelief (.a .b=1)(1/4=0), gen(anonbmis)
logit anonbmis i.itt edad edr estado

recode audiosat (.a .b=1)(1/5=0), gen(audiosatmis)
logit audiosatmis i.itt edad edr estado

* anonymity beliefs and non-response reported in paper body
tab nrvote anonbelief, col

* enjoyment and non-response reported in paper body
logit nrvote audiosat i.itt



***********************************
***		SUPPLEMENTAL MATERIAL	***
***********************************


*********************************
* BALANCE CHECKS - Table B1	
*********************************

* results referenced but not reported - without SE corrections for survey design:
* mlogit itt mujer i_o4 i.edr i.edad i.estado

svy: mlogit itt mujer i_o4 i.edr i.edad i.estado
eststo balance1
esttab balance1, b(3) se(3) nogaps nopar label 

svy: logit fbtreat mujer i_o4 i.edr i.edad i.estado if vb2==1
eststo balance2
esttab balance2, b(3) se(3) nogaps nopar label 



**************************
* APPENDIX TABLE C1
**************************

* ROBUSTNESS CHECKS: RESULTS CLUSTERED BY INTERVIEWER, WITH SURVEY WEIGHTS, ROBUST SE'S
* WITH AND WITHOUT CONTROLS

logit nrvote i.itt
eststo m1
logit nrvote i.itt, cluster(srvyrid)
eststo m2
svy: logit nrvote i.itt
eststo m3
logit nrvote i.itt edad edr estado
eststo m4
logit nrvote i.itt edad edr estado, cluster(srvyrid)
eststo m5
svy: logit nrvote i.itt edad edr estado
eststo m6

esttab m1 m2 m3 m4 m5 m6, b(3) se(3) nogaps nopar label 


**************************
* APPENDIX TABLE C2
**************************

*chi-squared and Z scores are reported in the margins command above
esttab privacy1 privacy2 audiotrt1 audiotrt2 , b(3) se(3) nogaps nopar label 


**************************
* APPENDIX TABLE C3 & C4 
**************************

logit AMLO i.itt edad edr if estado==1001
eststo c32
margins i.itt, atmeans post
test 1.itt==.577
test 2.itt==.577
test 3.itt==.577
test 4.itt==.577
test 5.itt==.577
test 6.itt==.577
eststo amlo1001_2

logit AMLO i.itt edad edr if estado==1002
eststo c34
margins i.itt, atmeans post
test 1.itt==.544
test 2.itt==.544
test 3.itt==.544
test 4.itt==.544
test 5.itt==.544
test 6.itt==.544
eststo amlo1002_2

* TABLE C3
esttab c31 c32 c33 c34, b(3) se(3) nogaps nopar label 

*TABLE C4
esttab amlo1001 amlo1001_2 amlo1002 amlo1002_2 , b(3) se(3) nogaps nopar label 


**************************
* APPENDIX TABLE C5
**************************
svy: logit nrvote i.itt 
estat effects
svy: logit nrvote i.itt edad edr estado
estat effects

preserve
svyset srvyrid
svy: logit nrvote i.itt 
estat effects
svy: logit nrvote i.itt edad edr estado
estat effects
restore 



*********************************
* APPENDIX TABLE D1
*********************************

* creating summary measures for each interviewer

recode itt(1/2=0)(3/6=1), gen(anytreat)
* respondents assigned to an audio condition
bys srvyrid: egen audioasst = sum(anytreat) if vb2==1
* sum reassigned
bys srvyrid: egen reassignedn = sum(reassigned) if vb2==1
* proportion of all assigned that were reassigned 
bys srvyrid: gen reassignedper = reassignedn/audioasst if vb2==1

* respondents assigned to an audio condition - soccer
bys srvyrid: egen fbassign = sum(fbtreat) 
* sum reassigned
bys srvyrid: egen reassignedn_f = sum(reassigned_fbl) 
* proportion of all assigned that were reassigned 
bys srvyrid: gen reassignedper_f = reassignedn_f/fbassign 

* values for table:
list srvyrid reassignedn audioasst reassignedper reassignedn_f fbassign reassignedper_f


*********************************
* APPENDIX TABLE D2
*********************************

ttest q2 if vb2==1, by(reassigned) 
ttest ed if vb2==1, by(reassigned) 
ttest mujer if vb2==1, by(reassigned) 

ttest q2 if vb2==1, by(reassigned_fbl) 
ttest ed if vb2==1, by(reassigned_fbl) 
ttest mujer if vb2==1, by(reassigned_fbl) 

*********************************
* APPENDIX TABLE D3
*********************************

ttest nrvote if vb2==1 & inlist(itt, 3, 4, 5, 6), by(reassigned)


**********************
* APPENDIX TABLE E1
**********************

reg anonbelief treat3 if itt<5
eststo anonb1
reg anonbelief treat3
eststo anonb2
reg anonbelief privacytrt i.anonymous
eststo anonb3
reg anonbelief treat3 privacytrt i.anon2
eststo anonb4

esttab anonb1 anonb2 anonb3 anonb4, b(3) se(3) nogaps nopar label 

**********************
* APPENDIX TABLE E2
**********************
logit nrfutbol i.fbtreat if vb2==1
logit nrfutbol i.fbtreat if vb2==2

ttest nrfutbol if vb2==1, by(fbtreat)
ttest nrfutbol if vb2==2, by(fbtreat)


**********************
* APPENDIX TABLE E3
**********************

*column 1
reg audiosat 0.fbtreat if vb2==1

*column 2
reg audiosat i.fbtreat edad edr estado if vb2==1

*column 3
reg svysat i.treat3 i.fbtreat edad edr estado if vb2==1

*column 4
reg svysat i.fbtreat edad edr estado if vb2==2


**********************
* APPENDIX TABLE E4
**********************

logit nrfutbol i.fbtreat##i.mujer if vb2==1
eststo nrfbm1
logit nrfutbol i.fbtreat##i.mujer if vb2==2
eststo nrfbm2

esttab nrfbm1 nrfbm2, b(3) se(3) nogaps label 


*********************************
* FIGURE F1
*********************************

gen itt2=itt
lab define itt2 1 "Control" 2 "Interviewer+Reminder" 3 "Audio, No Reminder" 4 "Audio, C. Reminder" ///
	5 "Audio, A. Guarantee" 6 "Audio, A&C Assurances"
lab val itt2 itt2

destring amlo_vovte, generate(amlovote) percent
bys municipio itt: egen meanamlo=mean(AMLO) if itt!=.

twoway (scatter meanamlo amlovote, by(itt2)  ytitle("AMLO Vote (survey reports)") ///
		xtitle("AMLO Vote (official) ") ///
		xlabel(.4 .5 .6 .7) subtitle(, size(small))) ///
		(lfit meanamlo amlovote, by(itt2)) (scatteri .4 .4 .7 .7 , connect(l) ///
		clwidth(thin) msymbol(i) legend(cols(3) label(1 "Observed Values") ///
		label(2 "Fitted Values") label(3 "Perfect Prediction (x=y)")))

